"""space model"""
from django.db import models
from .base import TimeModel
from .organization import User

class SpecialInterestGroup(TimeModel):
    name = models.CharField(max_length=128, unique=True, help_text='sig组名')

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'space_specialinterestgroup'


class Repository(TimeModel):
    name = models.CharField(max_length=128, unique=True, help_text='仓名')
    sig = models.ForeignKey(
        SpecialInterestGroup, 
        on_delete=models.PROTECT, 
        related_name='repositories', 
        related_query_name='repository', 
        help_text='所属sig组',
        )
    owner = models.ForeignKey(
        User, 
        on_delete=models.PROTECT, 
        related_name='repositories', 
        related_query_name='repository', 
        help_text='责任人',
        )

    def __str__(self):
        return f'{self.name}-{self.owner.username}'

    class Meta:
        db_table = 'space_repository'